<!--
	作者：956911785@qq.com
	时间：2019年5月18日11:34:11
	描述：社团活动辅导班-添加
-->

<template>
	<Modal :title="title" v-model="modal0" width="500px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:200px; overflow-y: hidden;">
				
				<div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 100%;text-align: left;float: left;" align="left">
				        <FormItem  label="请选择账号类型">
				        	<RadioGroup v-model="utype" @on-change="changZhlx">
				        		<Radio label="学校账号"></Radio>
						        <Radio label="地区账号"></Radio>
						    </RadioGroup>
		        		</FormItem>
		        	</div>
		       </div>
		       
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 100%;text-align: left;float: left;" align="left">
				        <FormItem label="学校">
				        	<Select v-model="params.csid" style="width:90%;float:left;" clearable :disabled="csdisable" transfer>
						        <Option v-for="item in campus" :value="item.CSID" :key="item.CSNAME">{{ item.CSNAME }}</Option>
						    </Select>
		        		</FormItem>
		        	</div>	
		        </div>
		        
		        
		        <div style="width:100%;height: 60px;line-height: 60px;float:left;">
		        	<div style="width: 100%;text-align: left;float: left;" align="left">
				        <FormItem prop="usname" label="账号名">
				        	<Input v-model="params.usname" placeholder="请输入账号名" clearable style="width: 90%"></Input>
		        		</FormItem>
		        	</div>	
		        </div>
		        
		     
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="addsave()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>

	
	export default {
		name:"tconent",
		props: {
    		teas:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    		title:{
    			type:String,	
    		},
    	},
		data(){
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
			return {
				ruleValidate: {
		            usname: [
		                {required: true, message: '请输入账号名！', trigger: 'blur'},
		                {length:30,validator:lenPass,trigger:'blur'}
		            ],
		        },   
                modal0:false,
                utype:'学校账号',
                csdisable:false,
                params:{
                	usid:'', 
					usname:'', 
					csid:'',
                },
			}
		},
		methods: {
			addsave(){
				if(!this.csdisable){
					if(!this.params.csid){
						this.$Modal.error({
                            title: "失败",
                            content: "添加学校账号,请选择学校！"
                        });
                        return;
					}
				}
				this.$refs.params.validate((valid) => {
					if (valid){
						const params={...this.params};
						this.$emit("addsave",params);
                    }
                })
	        }, 
			
            closeModal(){
	      	    this.modal0 = false;
	      	    this.resetpar();
	        },
	        resetpar(){
	        	this.params={
	        		usid:'', 
					usname:'', 
					csid:'', 
				};
	        },
	        
	        changZhlx(){
	        	var utype=this.utype;
	        	if(utype=="学校账号"){
	        		this.csdisable=false;
	        	}else{
	        		this.params.csid='';
	        		this.csdisable=true;
	        	}
	        }
	   
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				if(!news){
					this.resetpar();
				}else{
					if(this.teas.csid){
						this.csdisable=false;
						this.utype="学校账号";
					}else if(this.teas.usname){
						this.csdisable=true;
						this.utype="地区账号";
					}
					this.params={...this.teas};
				}
			}
		},
		computed: {
			campus: function() {
				return this.$store.state.app.campus;
			}
		}
		
	}
</script>

<style scoped="scoped">
	
</style>



